package com.cheung.leetcode.dp;

import org.junit.jupiter.api.Test;

public class Code509Test {
    public int fib(int n) {
        if (n <= 1) {
            return n;
        }
        int a = 0, b = 1;
        for (int i = 2; i <= n; i++) {
            int c = a + b;
            a = b;
            b = c;
        }

        return b;
    }


    @Test
    public void test1() {
        assert 1 == fib(2);
    }

    @Test
    public void test2() {
        assert 2 == fib(3);
    }

    @Test
    public void test3() {
        assert 3 == fib(4);
    }

}
